package org.summerframework.component.note.template.controller;

import org.summerframework.component.note.template.service.NoteTemplateService;
import org.summerframework.component.note.template.service.dto.NoteTemplateDTO;
import org.summerframework.component.note.template.service.dto.NoteTemplateQueryDTO;
import org.summerframework.component.security.annotion.RoleRequired;
import org.summerframework.component.security.controller.BaseController;
import org.summerframework.core.base.result.ResultDTO;
import org.summerframework.core.page.PageResult;
import org.summerframework.core.util.OptionalUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.List;
import javax.annotation.Resource;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;

@RoleRequired
@RestController
@Api(tags = "短信模板", description = "功能描述")
@RequestMapping("noteTemplate")
public class NoteTemplateController extends BaseController {
    @Resource
    private NoteTemplateService noteTemplateService;

    @PostMapping
    @ApiOperation("添加")
    public ResultDTO<Boolean> insert(NoteTemplateDTO noteTemplateDTO) {
        return ResultDTO.ok(true, noteTemplateService.insert(noteTemplateDTO));
    }

    @PutMapping
    @ApiOperation("更新")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = true, dataType = "Long", paramType = "query")})
    public ResultDTO<Integer> updateById(NoteTemplateDTO noteTemplateDTO) {
        return ResultDTO.ok(noteTemplateService.updateById(noteTemplateDTO));
    }

    @DeleteMapping("{id}")
    @ApiOperation("根据id删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = true, dataType = "Long", paramType = "path")})
    public ResultDTO<Integer> deleteById(@PathVariable("id") Long id) {
        return ResultDTO.ok(noteTemplateService.deleteById(id));
    }

    @DeleteMapping
    @ApiOperation("根据id列表删除删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "根据ids删除", required = true, dataType = "List", paramType = "query")})
    public ResultDTO<Integer> deleteByIds(@RequestParam("ids") List<Long> ids) {
        return ResultDTO.ok(noteTemplateService.deleteByIds(ids));
    }

    @GetMapping("{id}")
    @ApiOperation("根据id查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = true, dataType = "Long", paramType = "path")})
    public ResultDTO<NoteTemplateDTO> selectById(@PathVariable("id") Long id) {
        return ResultDTO.ok(OptionalUtils.get(noteTemplateService.selectById(id)));
    }

    @GetMapping
    @ApiOperation("根据query查询")
    public PageResult<NoteTemplateDTO> selectPageResultByQuery(NoteTemplateQueryDTO noteTemplateQueryDTO) {
        return noteTemplateService.selectPageResultByQuery(noteTemplateQueryDTO);
    }
}
